Skip to content

Add devtunnel connection for debugger jobs#4317

Open
rentziass wants to merge 10 commits intomainfrom
feature/devtunnel-dap-runner
Open

Add devtunnel connection for debugger jobs#4317
rentziass wants to merge 10 commits intomainfrom
feature/devtunnel-dap-runner

Conversation

@rentziass
Copy link
Copy Markdown
Member

@rentziass rentziass commented Mar 27, 2026

This PR adds remote debugger connectivity to the runner via Dev Tunnels. The runner now deserializes the DebuggerTunnel payload (tunnel ID, cluster, host token, port) from the job message, binds the DAP server to the tunnel-provided port, and starts a Dev Tunnel relay so remote DAP clients can connect. The DAP port is now mandated by the backend for two reasons:

  • the token the runner gets doesn't allow it to manage the dev tunnel (and for example add other ports)
  • forcing the runner to use port 4711 (failing the job if not available) makes sure we don't relay something that isn't the DAP server over Dev Tunnel

Since we're adding more debugger configuration this also changes the previous EnableDebugger bool in context with an object carrying that configuration.

https://github.com/github/c2c-actions/issues/9831

@rentziass rentziass marked this pull request as ready for review March 27, 2026 16:32
@rentziass rentziass requested a review from a team as a code owner March 27, 2026 16:32
Copilot AI review requested due to automatic review settings March 27, 2026 16:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Dev Tunnels–based remote connectivity for debugger (DAP) jobs by extending the job message contract with tunnel details and updating the worker-side debugger startup to bind to the tunnel-provided port and start a tunnel relay.

Changes:

  • Extend AgentJobRequestMessage with DebuggerTunnel payload deserialization (tunnel ID/cluster/token/port) and add the DebuggerTunnelInfo contract type.
  • Replace GlobalContext.EnableDebugger with a consolidated DebuggerConfig (enabled + tunnel info) and update debugger enablement checks accordingly.
  • Update DapDebugger to require a valid tunnel config, bind to the tunnel port, and start/stop a Dev Tunnel relay; adjust L0 tests to use the new config model.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Test/L0/Worker/DapDebuggerL0.cs Updates L0 tests to use tunnel-based debugger config and skips relay during unit tests.
src/Test/L0/Sdk/RSWebApi/AgentJobRequestMessageL0.cs Adds deserialization tests for the new DebuggerTunnel payload.
src/Sdk/DTPipelines/Pipelines/DebuggerTunnelInfo.cs Introduces the tunnel info DataContract used in job messages.
src/Sdk/DTPipelines/Pipelines/AgentJobRequestMessage.cs Adds DebuggerTunnel DataMember to the job request message.
src/Runner.Worker/Runner.Worker.csproj Adds Microsoft.DevTunnels.Connections dependency for relay hosting.
src/Runner.Worker/JobRunner.cs Switches debugger enablement check to Global.Debugger?.Enabled.
src/Runner.Worker/GlobalContext.cs Replaces EnableDebugger with DebuggerConfig Debugger.
src/Runner.Worker/ExecutionContext.cs Populates Global.Debugger from EnableDebugger + DebuggerTunnel in the acquire response.
src/Runner.Worker/Dap/DebuggerConfig.cs Adds consolidated debugger configuration and tunnel validity check.
src/Runner.Worker/Dap/DapDebugger.cs Requires valid tunnel config, binds to tunnel port, and starts/stops Dev Tunnel relay.

/// Useful when third-party libraries require a <see cref="System.Diagnostics.TraceSource"/>
/// to route their diagnostics into the runner's log infrastructure.
/// </summary>
public TraceSource Source => _traceSource;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work? are we able to get log from the AzureSDK into the runner diag log?

};

_tunnelRelayHost = new TunnelRelayTunnelHost(managementClient, HostContext.GetTrace("DevTunnelRelay").Source);
using var connectCts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the 30s good enough? do we need to make this configureable in case the tunnel connection is flaky?
ignore this comment if we know the connect is super reliable and the P99.9 is less than 5s. 😄

Trace.Info("Dev Tunnel relay stopped");
}
}
catch (Exception ex)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need the catch, what code might throw?

HandleClientDisconnected();
CleanupConnection();
}
catch (ObjectDisposedException)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are catching ObjectDisposedException, we might have something doing wrong since we shouldn't dispose an object if we are stilling using it somewhere else, dispose should be the last thing to call when everything has stopped.

&& !string.IsNullOrEmpty(Tunnel.TunnelId)
&& !string.IsNullOrEmpty(Tunnel.ClusterId)
&& !string.IsNullOrEmpty(Tunnel.HostToken)
&& Tunnel.Port >= 1024;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& <= 65535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants